import { createRouter, createWebHistory } from "vue-router";

const routes = [
    {
        path: "/admin",
        component: () => import("@/views/admin/admin.vue"),
        children: [
            {
                path: '',
                component: import("@/views/admin/sub/index.vue")
            },
            {
                path: 'users',
                component: import("@/views/admin/sub/users.vue")
            },
        ]
    },
    {
        path: "/",
        component: () => import("@/views/web/web.vue"),
        children: [
            {
                path: '',
                component: import("@/views/web/sub/demo1.vue")
            },
            {
                path: 'demo2',
                component: import("@/views/web/sub/demo2.vue")
            },
            {
                path: 'demo3',
                component: import("@/views/web/sub/demo3.vue")
            },
            {
                path: 'demo4',
                component: import("@/views/web/sub/demo4.vue")
            },
            {
                path: 'notice',
                component: import("@/views/web/sub/concernlist/notice.vue")
            },
            {
                path: 'ground',
                component: import("@/views/web/sub/concernlist/ground.vue")
            },
            {
                path: 'leaderboard',
                component: import("@/views/web/sub/concernlist/leaderboard.vue")
            },
            {
                path: 'follow',
                component: import("@/views/web/sub/concernlist/follow.vue")
            },
        ]
    },
    {
        path: "/login",
        component: () => import("@/views/web/login.vue")
    },
    {
        path: "/reg",
        component: () => import("@/views/web/reg.vue")
    },
    {
        path: "/search",
        component: () => import("@/views/web/search.vue"),
        name: 'search'
    },
    {
        path: "/searchshoucang",
        component: () => import("@/views/web/searchshoucang.vue"),
        name: 'searchshoucang'
    },
    {
        path: "/Gnerateshoucang",
        component: () => import("@/views/web/Gnerateshoucang.vue"),
        name: 'Gnerateshoucang'
    },
    {
        path: "/setting",
        component: () => import("@/views/web/sub/demo4-vue/Setting.vue")
    },
    {
        path: "/release",
        component: () => import("@/views/web/sub/demo4-vue/Release.vue")
    },
    {
        path: "/follow",
        component: () => import("@/views/web/sub/demo4-vue/Follow.vue")
    },
    {
        path: "/fans",
        component: () => import("@/views/web/sub/demo4-vue/Fans.vue")
    },
    {
        path: "/person",
        component: () => import("@/views/web/sub/demo4-vue/PersonalData.vue")
    },
    {
        path: "/account",
        component: () => import("@/views/web/sub/demo4-vue/Account.vue")
    },
    {
        path: "/notes",
        component: () => import("@/views/web/sub/demo4-vue/Notes.vue")
    },
];

const router = createRouter({
    history: createWebHistory(),
    routes
});

router.beforeEach((to, from, next) => {
    // 如果目标路径是首页，并且没有特定的选项卡状态，则默认设置为“今日推荐”
    if (to.path === '/' && !to.query.tab) {
        to.query = { tab: '1' }; // 设置默认选项卡为“今日推荐”
    }
    next();
});

export default router;